package com.shqcjd.sinopecdemomobile.ui.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shqcjd.sinopecdemomobile.R;
import com.shqcjd.sinopecdemomobile.model.pojo.EquipmentListBean;

import java.util.List;

public class EquipmentListAdapter extends BaseQuickAdapter<EquipmentListBean.ItemsBean,EquipmentListAdapter.ViewHolder> {
    private Context context;
    public EquipmentListAdapter(@Nullable List<EquipmentListBean.ItemsBean> data, Context context) {
        super(R.layout.item_equipment_list, data);
        this.context = context;
    }

    @Override
    protected void convert(ViewHolder helper, EquipmentListBean.ItemsBean item) {
        helper.tv_item_equipment_list_code.setText((helper.getAdapterPosition()+1)+"");
        helper.tv_item_equipment_list_name.setText(item.name);
        String str="7天内<br/>完成<font color='#F25858'>"+item.check_times+"</font>次巡检";
        helper.tv_item_equipment_list_time.setText(Html.fromHtml(str));
        helper.tv_item_equipment_list_kks.setText(item.kks);
        helper.tv_item_equipment_list_temperature.setText(item.check_value);
        helper.tv_item_equipment_list_type.setText(item.manufacturer);

        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.ic_default_small)	//加载成功之前占位图
                .error(R.mipmap.ic_default_small);//指定图片的缩放类型为centerCrop （等比例缩放图片，直到图片的宽高都
        Glide.with(context)
                .load(item.img)
                .apply(options)
                .into(helper.iv_item_equipment_list_pic);

        helper.addOnClickListener(R.id.btn_inspection);
    }

    class ViewHolder extends BaseViewHolder {
        private TextView tv_item_equipment_list_code, tv_item_equipment_list_name, tv_item_equipment_list_type,
                tv_item_equipment_list_temperature, tv_item_equipment_list_kks, tv_item_equipment_list_time;
        private ImageView iv_item_equipment_list_pic;
        private Button btn_inspection;

        ViewHolder(View itemView) {
            super(itemView);
            tv_item_equipment_list_code = itemView.findViewById(R.id.tv_item_equipment_list_code);
            tv_item_equipment_list_name = itemView.findViewById(R.id.tv_item_equipment_list_name);
            tv_item_equipment_list_type = itemView.findViewById(R.id.tv_item_equipment_list_type);
            tv_item_equipment_list_temperature = itemView.findViewById(R.id.tv_item_equipment_list_temperature);
            tv_item_equipment_list_kks = itemView.findViewById(R.id.tv_item_equipment_list_kks);
            tv_item_equipment_list_time = itemView.findViewById(R.id.tv_item_equipment_list_time);
            iv_item_equipment_list_pic = itemView.findViewById(R.id.iv_item_equipment_list_pic);
            btn_inspection = itemView.findViewById(R.id.btn_inspection);
        }
    }
}
